import _ from "lodash";
import { getCustomerAsync } from "@utils";

import service from "@service";

export default {
    namespaced: true,
    state: {
        customer: null
    },
    mutations: {
        SET_CUSTOMER(state, payload) {
            state.customer = payload;
        },
        CLEAR_CUSTOMER(state, payload) {
            state.customer = null;
        },
    },
    actions: {
        async getCustomer({state, commit}, vm) {
            if(state.customer) {
                return state.customer;
            }
            let customer = await getCustomerAsync(vm, {});
            if(customer && customer.length) {
                commit('SET_CUSTOMER', customer[0]);
            }
            return state.customer;
        }
    },
    getters: {
        
    },
};
